import axios, { AxiosError, AxiosResponse } from "axios";
import { ElMessage } from "element-plus";
// @ts-ignore
export const baseURL = `${window.baseurl}/api`;

export interface Result<T = any> {
	success: boolean;
	error: {
		detail: string;
		message: string;
	};
	sysSuccess: boolean;
	resultInfo: T;
	total?: number;
}
const service = axios.create({
	baseURL: baseURL,
	timeout: 1000,
	timeoutErrorMessage: "请求超时",
});

service.interceptors.request.use(
	(config) => {
		return config;
	},
	(error) => {
		Promise.reject(error);
	}
);

service.interceptors.response.use(
	(response: AxiosResponse) => response.data,
	async (error: AxiosError) => {
		if (error.response?.status === 401) {
			ElMessage.error("");
		}
		return error;
	}
);

export default service;
